package com.example.springaop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.beans.Transient;

@Slf4j
@Component
@Aspect
@Order(3)
public class AspectDemo {
    @Pointcut("execution(* com.example.controller.*.*(..))")
    public void pt(){};
    @Before("pt()")
    public void doBefore(){
        log.info("方法执行前 doBefore()");
    }

    @After("execution(* com.example.controller.*.*(..))")
    public void doAfter(){
        log.info("方法执行后 doAfter()");
    }

    @Around("execution(* com.example.controller.*.*(..))")
    public Object doAround(ProceedingJoinPoint pj) throws Throwable {
        log.info("方法执行前 doAround()");
        Object result = pj.proceed();
        log.info("方法执行后 doAround()");
        return result;
    }

    @AfterReturning("execution(* com.example.controller.*.*(..))")
    public void doAfterReturn(){
        log.info("方法执行后 doAfterReturn()");
    }

    @AfterThrowing("execution(* com.example.controller.*.*(..))")
    public void doAfterThrow(){
        log.info("方法执行后 doAfterThrow()");

    }
}
